﻿namespace OP10.ViewModels
{
    public class ST04WeldCheckViewViewMdoel : BindableBase
    {


        private readonly IRegionManager _regionManager;

        public ST04WeldCheckViewViewMdoel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            TestResistance = TestMachine_Global.nCheckResist;
            Deviation = TestMachine_Global.nCheckOffset;
            //开启定时器任务
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            dispatcherTimer.Tick += OnTick;
            dispatcherTimer.Start();
        }

        private void OnTick(object? sender, EventArgs e)
        {
            CurrentPull = WirePLCToPC_Global.ActualTension;
            CurrentResistance = TestMachinePLCToPC_Global.nCurrentResist;
            DisplayResistance = TestMachinePLCToPC_Global.nCheckResultValue;
        }



        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST04DeviceManagerView);
        }



        private DelegateCommand _ST03WeldTestDownCmd;
        public DelegateCommand ST03WeldTestDownCmd =>
            _ST03WeldTestDownCmd ?? (_ST03WeldTestDownCmd = new DelegateCommand(ExecuteST03WeldTestDownCmd));

        void ExecuteST03WeldTestDownCmd()
        {

        }


        private DelegateCommand _ST03WeldTestUpCmd;
        public DelegateCommand ST03WeldTestUpCmd =>
            _ST03WeldTestUpCmd ?? (_ST03WeldTestUpCmd = new DelegateCommand(ExecuteST03WeldTestUpCmd));

        void ExecuteST03WeldTestUpCmd()
        {

        }


        private DelegateCommand _ST3OpenLightCommand;
        public DelegateCommand ST3OpenLightCommand =>
            _ST3OpenLightCommand ?? (_ST3OpenLightCommand = new DelegateCommand(ExecuteST3OpenLightCommand));

        void ExecuteST3OpenLightCommand()
        {
            CCDPCToPLC_Global.ST3LightBT = true;

        }

        private DelegateCommand _ST3UnOpenLightCommand;
        public DelegateCommand ST3UnOpenLightCommand =>
            _ST3UnOpenLightCommand ?? (_ST3UnOpenLightCommand = new DelegateCommand(ExecuteST3UnOpenLightCommand));

        void ExecuteST3UnOpenLightCommand()
        {
            CCDPCToPLC_Global.ST3LightBT = false;

        }


        private DelegateCommand _ST5OpenLightCommand;
        public DelegateCommand ST5OpenLightCommand =>
            _ST5OpenLightCommand ?? (_ST5OpenLightCommand = new DelegateCommand(ExecuteST5OpenLightCommand));

        void ExecuteST5OpenLightCommand()
        {
            CCDPCToPLC_Global.ST5LightBT = true;

        }



        private DelegateCommand _ST5UnOpenLightCommand;
        public DelegateCommand ST5UnOpenLightCommand =>
            _ST5UnOpenLightCommand ?? (_ST5UnOpenLightCommand = new DelegateCommand(ExecuteST5UnOpenLightCommand));

        void ExecuteST5UnOpenLightCommand()
        {
            CCDPCToPLC_Global.ST5LightBT = false;

        }
        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            if (p== "TestResistance")
            {
                 TestMachine_Global.nCheckResist= TestResistance;
            
            }
            else if (p== "Deviation")
            {
               TestMachine_Global.nCheckOffset = Deviation ;
            }
        }
        #endregion


        #region 属性
        private float _CurrentPull;
        public float CurrentPull
        {
            get { return _CurrentPull; }
            set { SetProperty(ref _CurrentPull, value); }
        }


        private float _CurrentResistance;
        public float CurrentResistance
        {
            get { return _CurrentResistance; }
            set { SetProperty(ref _CurrentResistance, value); }
        }


        private float _TestResistance;
        public float TestResistance
        {
            get { return _TestResistance; }
            set { SetProperty(ref _TestResistance, value); }
        }


        private float _Deviation;
        public float Deviation
        {
            get { return _Deviation; }
            set { SetProperty(ref _Deviation, value); }
        }


        private float _DisplayResistance;
        public float DisplayResistance
        {
            get { return _DisplayResistance; }
            set { SetProperty(ref _DisplayResistance, value); }
        }
        #endregion
    }
}

